<template>
	<view class="slide-main">
		<view class="list" v-for="(item,index) in renderData" :key="index">
			<liu-swipe-action :index="index" @clickItem="clickItem(item,$event)">
				<view class="item">
					<view>{{item.name}}</view>
					<!-- <image class="item-img" src="https://cdn.pixabay.com/photo/2022/03/31/14/53/camp-7103189_1280.png">
                    </image> -->
					<view class="item-name">
						<view class="manBox">
							负责人：{{item.responsibleUser.name}}
						</view>
						<view class="manBox">检查人：{{item.completeUserName}}</view>
					</view>
				</view>
			</liu-swipe-action>
		</view>
		<view class="btnBox">
			<button class="btn" @click="toAdd">安排任务</button>
		</view>
	</view>
</template>

<script>
	import {
		baseURL
	} from '@/api/env.js'
	export default {
		data() {
			return {
				list: [{
					id: 1,
					name: '任务1',
					leader: '韩朵朵',
					checkMan: '刘培强',
					date: '2023-09-18',
					type: 0,
					content: '内容1'
				}, {
					id: 2,
					name: '任务2',
					leader: '韩朵朵',
					checkMan: '刘培强',
					date: '2023-10-18',
					type: 1,
					content: '内容2'
				}],
				renderData: []
			}
		},
		onLoad() {
			this.getTaskInfoList()
			this.renderData = this.list
			uni.$on('refreshPreviousPage', (data) => {
				this.refreshPage(data.data)
				this.renderData.forEach(el => {
					if (el.id == data.data.id) {
						el.name = data.data.name
						el.type = data.data.type
						el.date = data.data.date
						el.content = data.data.content
					}
				})
			})
		},
		methods: {
			//点击操作回调事件
			clickItem(item, e) {
				console.log('eeitem', e);
				console.log('所点击的列表索引：' + e.index)
				console.log('所点击的按钮id：' + e.id) // 1修改2删除
				if (e.id == 1) {
					// 编辑
					uni.navigateTo({
						url: '/pages/taskMg/arrangeTask/addArrageTask/addArrageTask?item=' + JSON.stringify(item)
					})
				} else {
					// 删除
					console.log('shanchu')
					// this.renderData = this.list.filter(el => {
					// 	return el.id != e.index + 1
					// })[0]
					this.deleteTaskInfo(item.id)
				}
			},
			// 新增
			toAdd() {
				uni.navigateTo({
					url: '/pages/taskMg/arrangeTask/addArrageTask/addArrageTask'
				})
			},
			refreshPage(data) {
				// 执行刷新页面的操作，并设置data值
				this.dataValue = data;
			},
			/**
			 *接口
			 * /
			 */
			getTaskInfoList(pageNum = 1, pageSize = 10, userId = uni.getStorageSync('userId')) {
				let params = {
					pageNum,
					pageSize,
					userId
				}
				console.log('PARAMS', params);
				uni.request({
					url: baseURL + '/api/task/info/page',
					method: "GET",
					header: {
						// "content-type": "appLication/x-www-form-urlencoded",
						'Authorization': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log('RES', res);
						if (res.data.code == 200) {
							this.renderData = res.data.data.records
							this.total = res.data.data.total
						}
					}
				})
			},
			deleteTaskInfo(id) {
				uni.request({
					url: baseURL + '/api/task/info/delete/' + id,
					method: "GET",
					header: {
						// "content-type": "appLication/x-www-form-urlencoded",
						'Authorization': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log('RES', res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '删除成功',
								icon: 'success', //将值设置为 success 或者 ''
								duration: 1500 //持续时间为 2秒
							})
							this.getTaskInfoList()
							// this.renderData = res.data.data.records
							// this.total = res.data.data.total
						} else {
							uni.showToast({
								title: '删除失败',
								icon: '', //将值设置为 success 或者 ''
								duration: 1500 //持续时间为 2秒
							})
						}
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.slide-main {
		width: 100%;
		height: 90vh;
		overflow-y: auto;
		/* background-color: #f0f0f0; */
	}

	.list {
		width: 100%;
		margin-top: 1px;
	}

	.item {
		width: calc(100% - 40rpx);
		height: 120rpx;
		font-size: 1.2rem;
		background-color: #ffffff;
		margin: 0 20rpx 20rpx 20rpx;
		padding: 20rpx;
		border-radius: 10rpx;
		border: 2rpx solid #d5d5d5;
		// box-shadow: 10rpx 8rpx 10rpx black;

		display: flex;
		flex-direction: column;
		/* align-items: center; */
		justify-content: space-around;
	}

	/* .item-img {
        width: 80rpx;
        height: 80rpx;
        border-radius: 50%;
        margin-left: 28rpx;
    } */

	.item-name {
		font-size: 0.8rem;
		color: #d4d4d4;
		display: flex;
		flex-direction: row;

		.manBox {
			width: 40%;
		}
	}

	.btnBox {
		position: fixed;
		bottom: 5%;

		z-index: 1000;

		.btn {
			width: calc(100vw - 200rpx);
			height: 80rpx;
			line-height: 80rpx;
			font-size: 0.8rem;
			color: white;
			margin-left: 100rpx;
			border-radius: 40rpx;
			background-color: #409EFF;
		}
	}
</style>